const app = getApp()
Page({
  data: {
    avatarUrl: './user-unlogin.png',
    userInfo: null,
    logged: false,
    takeSession: false,
    requestResult: '',
    // chatRoomEnvId: 'release-f8415a',
    chatRoomCollection: 'chatroom',
    chatRoomGroupId: '',
    chatRoomGroupName: '',
    id: '',

    // functions for used in chatroom components
    onGetUserInfo: null,
    getOpenID: null,
  },

  onLoad: function(options) {
    // 获取用户信息
    let userinfo = wx.getStorageSync('userInfo');
    if(userinfo){
     this.setData({
        avatarUrl: userinfo.head_pic,
        userInfo:userinfo
     })
   }
  //  wx.removeStorageSync('userinfo')
    this.setData({
      onGetUserInfo: this.onGetUserInfo,
      getOpenID: this.getOpenID,
      chatRoomGroupId:options.gid,
      chatRoomGroupName: options.name,
      id: options.id
    })
    // console.log(this.data.id);
  },

  getOpenID: async function() {
    if (this.openid) {
      return this.openid
    }

    const { result } = await wx.cloud.callFunction({
      name: 'getOpenIDRoom',
    })

    return result.openid
  },

  onShareAppMessage() {
    return {
      title: '即时通信 Demo',
      path: '/pages/im/room/room',
    }
  },
  onReady() {
    
  }
})
